package com.spring.cloud.server.controller;

import com.spring.cloud.server.service.DemoService;
import com.spring.cloud.server.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author li gang
 */
@RestController
public class Controller {

    @Autowired
    private RedisService redisService;

    @Autowired
    private DemoService demoService;

    @RequestMapping(value = "/")
    public String healthCheck() {
        return "server is ok";
    }

    @RequestMapping(value = "/get_info")
    public String getInfo(@RequestParam(value = "key") String key) {
        return this.redisService.getInformationByKey(key);
    }

    @RequestMapping(value = "/save_info")
    public void saveInfo(@RequestParam(value = "key") String key, @RequestParam(value = "value") String value) {
        this.redisService.saveInformation(key, value);
    }

    @RequestMapping(value = "/hello_world")
    public String helloWorld() {
        return this.demoService.getInformation();
    }

}
